/* Parallel Elliptic Curve Cryptography Engine - An OpenSSL Engine which
 * uses the SPU Elliptic Curve Library to provide optimized functionality
 * on the CBEA.
 *
 * Copyright (C) 2008  Michael Annichiarico (mike.gcdeveloper@gmail.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef PECC_STAGE4_SPUPPU_H
#define  PECC_STAGE4_SPUPPU_H

#ifdef __PPU__
#define __ea /* ignored */
#else
#include<ea.h>
#endif

typedef vector unsigned int vui;

#define ALIGNSIZE 16
//#define ALIGNSIZE 128

#define PECC_DMALIST_MAXSIZE 8
#define PECC_BN_WORDSIZE 2 /* actual */
//#define PECC_BN_WORDSIZE 1 /* debugging */

typedef struct spu_add_st {
vui r;
vui s;
vui a;
vui b;
vui m;
	int size;
} spu_add_t;
/*
typedef struct spu_add_st {
	__ea vui* r;
	__ea vui* s;
	__ea vui* a;
	__ea vui* b;
	__ea vui* m;
	int size;
} spu_add_t;
*/

typedef union PECC_BN_st {
	vui v[PECC_BN_WORDSIZE];
	unsigned int a[PECC_BN_WORDSIZE*4];
//	unsigned long long b[PECC_BN_WORDSIZE*2];
} PECC_BN_t __attribute__((aligned (ALIGNSIZE)));
/*
typedef struct PECC_BN_st {
	vui v[PECC_BN_WORDSIZE];
} PECC_BN_t __attribute__((aligned (ALIGNSIZE)));
*/

typedef struct spu_mod_mult_st {
	PECC_BN_t a;
	PECC_BN_t b;
	PECC_BN_t m;
	PECC_BN_t r;
	PECC_BN_t s;
} spu_mod_mult_t __attribute__((aligned (ALIGNSIZE)));

typedef struct spu_ecdsa_sign_st {
	PECC_BN_t d;
	PECC_BN_t e;
	PECC_BN_t k;
	PECC_BN_t r;
	PECC_BN_t s;
	signed int result __attribute__((aligned (16)));
} spu_ecdsa_sign_t __attribute__((aligned (16)));
typedef struct spu_ecdsa_verify_st {
	PECC_BN_t qx;
	PECC_BN_t qy;
	PECC_BN_t qz;
	PECC_BN_t e;
	PECC_BN_t r;
	PECC_BN_t s;
	signed int result __attribute__((aligned (16)));
} __attribute__((aligned (16))) spu_ecdsa_verify_t;

typedef struct spu_scalar_mult_st {
	PECC_BN_t s;
	PECC_BN_t x;
	PECC_BN_t y;
	PECC_BN_t z;
	signed int result __attribute__((aligned (16)));
} __attribute__((aligned (16))) spu_scalar_mult_t;

typedef struct spu_elem_st {
	union { unsigned long long all64; unsigned int by32[2]; } data;
	int size;
} __attribute__((aligned (ALIGNSIZE))) spu_elem_t;

typedef struct spu_list_st {
	spu_elem_t list[PECC_DMALIST_MAXSIZE];
	int size;
} spu_list_t __attribute__((aligned (ALIGNSIZE))) ;

typedef struct spu_cmd_st {
	int type;
	spu_elem_t arg;
} spu_cmd_t __attribute__((aligned (ALIGNSIZE)));


#endif

